/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  NativeModules,
  Button,
} from 'react-native';
import {AliLivingPusher} from "./node_modules/react-native-aliyun-living-pusher";
const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

type Props = {};
export default class App extends Component<Props> {
  startPreview = ()=>{
    // this.pusher && this.pusher.startPreview();
    NativeModules.AliLivingPusher.startPreview()
  }
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit App.js
        </Text>
        <Text style={styles.instructions}>
          {instructions}
        </Text>
        <AliLivingPusher
           ref={ref=>this.pusher=ref}
           onFirstFramePreviewed={()=>{
             console.log('已经开始渲染');
           }}
           onBeautySwitchOn={(isOn:Boolean)=>{
             console.log(`onBeautySwitchOn:${isOn}`);
           }}
           style={{width:100,height:100,backgroundColor: 'red',}}/>
        <Button title="开始预览" onPress={this.startPreview}>开始预览</Button>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});
